#include "AppDelegate.h"
#include "AppMacros.h"
#include "StartScene.h"
#include "SimpleAudioEngine.h"
#include "BCSManager.h"

USING_NS_CC;
using namespace CocosDenshion;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
	CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // Set the design resolution
    pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit);

	CCLog("des=(%f,%f);small=(%f,%f)", designResolutionSize.width, designResolutionSize.height, smallResource.size.width, smallResource.size.height);
	CCSize frameSize = pEGLView->getFrameSize();

   
	//CCFileUtils::sharedFileUtils()->setResourceDirectory(smallResource.directory);
	//pDirector->setContentScaleFactor(frameSize.height/designResolutionSize.height);
	//pDirector->setContentScaleFactor(designResolutionSize.height/frameSize.height);
	
    // turn on display FPS
    //pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);


    // run
    pDirector->runWithScene(StartScene::create());

	BCSManager::sharedBCSManager()->setAccessKey("0251436d44d3c9ea831ad8ea664df773");
	BCSManager::sharedBCSManager()->setSecretKey("18d72720fee06d6f5330a9b078d0931f");
	BCSManager::sharedBCSManager()->setBucket("xiaolian");
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
